close all
clear all

% Test AvpdCore::KeypointMemory::getLikelihood()

% load data
memory = dlmread('090306-3_db-Signatures.txt', ' ', 1, 0);
dictionary = dlmread('090306-3_db-Dictionary.txt', ' ', 1, 0);

%update the virtual place because the one included alredy in the memory is
%not updated with the last signature
[memory(1,:) dictionary] = updateCommonSignature(memory, dictionary);

sign = memory(end,:);
r = sum(sum((sign - [82,9,24,27,37,39,40,45,46,64,64,67,67,68,68,69,69,79,79,81,85,87,95,109,113,115,117,122,124,127,135,135,139,142,143,145,157,159,161,168,181,188,188,191,192,196,197,208,208,211,213,219,239,241,247,256,257,258,307,310,343,558,587,643,760,896,960,1019,1023,1074,1197,1207,1292,1401,1403,1587,2151,2419,2571,2623,2654,2664,2674,2674,2674,2777,2780,2796,2808,2835,2844,2844,2851,2855,2862,2900,3036,3143,3238,3238,3315,3531,3531,3766,3803,4296,4405,4462,4502,4506,4509,4509,4516,4523,4533,4533,4534,4535,4536,4537,4538,4539,4540,4541,4542,4543,4544,4545,4546,4547,4548,4549,4550,4551,4552,4553,4554,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;]) ~= 0)); 
if r ~= 0
    error('sign is not valid!')
end

likelihood = computeLikelihood(sign, memory, dictionary);
plot(likelihood)
likelihood = floor(likelihood*1000)
likelihood = likelihood';

r = sum(sum((likelihood - [109,157,263,203,87,66,78,49,60,40,47,43,43,55,102,102,147,0,38,61,64,74,69,103,39,20,44,33,14,14,20,12,18,8,59,19,41,26,45,117,124,173,223,74,0,10,17,53,33,24,33,43,52,68,119,124,146,159,28,68,59,115,71,95,37,18,16,49,9,28,20,9,15,11,10,35,45,73,18,92,167,219,1222;]) ~= 0)); 
if r ~= 0
    error('likelihood is not valid!')
end
